package nhatquang.gs.model;

import nhatquang.gs.controler.FruitManager;

import org.andengine.entity.modifier.MoveModifier;
import org.andengine.entity.modifier.SequenceEntityModifier;
import org.andengine.entity.sprite.Sprite;
import org.andengine.input.touch.TouchEvent;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.opengl.vbo.VertexBufferObjectManager;


public class FruitNomall extends Sprite {
	public boolean scale = false;

	private float endY;

	private int row;
	private int collumn;

	public int species;

//	private long T2 = 0;
//	private long T1 = 0;

	public static SequenceEntityModifier sequence;

	public FruitNomall(float pX, float pY, float pWidth, float pHeight,
			ITextureRegion pTextureRegion,
			VertexBufferObjectManager pVertexBufferObjectManager, int row,
			int collumn, float endY, int species) {
		super(pX, pY, pWidth, pHeight, pTextureRegion,
				pVertexBufferObjectManager);

		this.endY = endY;

		this.row = row;
		this.collumn = collumn;

		this.species = species;

//		moveSprite();

	}

	@Override
	public boolean onAreaTouched(TouchEvent pSceneTouchEvent,
			float pTouchAreaLocalX, float pTouchAreaLocalY) {
		if (FruitManager.INSTANCE.mOpenGame) {
			if (pSceneTouchEvent.isActionMove()
					|| pSceneTouchEvent.isActionDown()) {
				FruitManager.INSTANCE.checkFruit(FruitManager.INSTANCE.mapFruit[row][collumn]);
			}
		}
		return super.onAreaTouched(pSceneTouchEvent, pTouchAreaLocalX,
				pTouchAreaLocalY);
	}

	public void moveSprite() {

		float currentX = this.getX();
		float currentY = this.getY();

		 float duration = (endY-currentY)/Public.SPEED_SPRITE;

		 MoveModifier move = new MoveModifier(duration,
		 currentX,currentX,currentY,
		 endY);
		 this.registerEntityModifier(move);
	}

	public int getRow() {
		return row;
	}

	public void setRow(int row) {
		this.row = row;
	}

	public int getCollumn() {
		return collumn;
	}

	public void setCollumn(int collumn) {
		this.collumn = collumn;
	}

	public int getSpecies() {
		return species;
	}

	public void setSpecies(int species) {
		this.species = species;
	}

	public boolean isScale() {
		return scale;
	}

	public void setScale(boolean scale) {
		this.scale = scale;
	}

//	@Override
//	protected void onManagedUpdate(float pSecondsElapsed) {
//		T2 = System.currentTimeMillis();
//		if (scale && ((T2 - T1) >= 1000)) {
//			System.gc();
//			this.registerEntityModifier(new SequenceEntityModifier(
//					new ScaleModifier(0.5f, 1f, 1.3f), new ScaleModifier(0.5f,
//							1.3f, 1f)));
//			T1 = T2;
//		}
//		super.onManagedUpdate(pSecondsElapsed);
//	}
}
